34a35
> #include "ruim_ef_codec.h"
38a40,42
> #define PB_STORAGE_SM  "SM"
> #define PB_STORAGE_FD  "FD"
> 
134a139,379
> /*wupeng add begin.*/
> static void requestRSIMWritePbRecord(RIL* thiz, void* data, size_t datalen, RIL_Token t, const char* storage)
> {
> 	ATResponse *p_response = NULL;
>     RIL_SIM_IO_Response sr;
>     int ret;
>     char cmd[128] = {0};
>     RIL_SIM_IO_v5 *p_args;
>     char *line;
> 	PbookInfo pb_info;
> 	unsigned char* adnData;
> 
>     memset(&sr, 0, sizeof(sr));
>     p_args = (RIL_SIM_IO_v5 *)data;
> 
> 	if(p_args->pin2 == NULL) {
> 		snprintf(cmd, 32, "AT+CPBS=\"%s\"", storage);
> 	} else {
> 		snprintf(cmd, 32, "AT+CPBS=\"%s\",\"%s\"", storage, p_args->pin2);
> 	}
> 	ril_command_exec_for_result(thiz, cmd);
> 	memset(&pb_info, 0, sizeof(PbookInfo));
> 	if(p_args->data != NULL) 
> 	{
> 		adnData = StringToHex((unsigned char*)p_args->data, strlen(p_args->data));
> 		if(ruim_pbook_decode(adnData, strlen(p_args->data) / 2, &pb_info))
> 		{
> 			char* text = NULL;
> 
> 			if(pb_info.coding == RAW) {
> 				ril_command_exec_for_result(thiz, "AT+CSCS=\"UCS2\"");
> 				text = hexToString(pb_info.text, pb_info.text_len);
> 			} else {
> 				ril_command_exec_for_result(thiz, "AT+CSCS=\"GSM\"");
> 				text = strdup((char*)pb_info.text);
> 			}
> 
> 			if(pb_info.number_len == 0 && pb_info.text_len == 0)
> 			{
> 				snprintf(cmd, 128, "AT+CPBW=%d", p_args->p1);
> 			} else {
> 				snprintf(cmd, 128, "AT+CPBW=%d,\"%s\",%d,\"%s\"", p_args->p1,
> 					pb_info.number, pb_info.number_type, text);
> 			}
> 			if(ril_command_exec_for_result(thiz, cmd)) 
> 			{
> 				ret = 1;
> 			}
> 		}
> 		free(adnData);
> 	}
> 
> 	if(ret) {
> 		sr.sw1 = 0x90;
> 		sr.sw2 = 0x00;
> 		RIL_onRequestComplete(thiz, t, RIL_E_SUCCESS, &sr, sizeof(sr));
> 	} else {
> 		RIL_onRequestComplete(thiz, t, RIL_E_GENERIC_FAILURE, NULL, 0);
> 	}
> 
> 	return;
> }
> 
> int isHexStr(char *s)
> {
> 	while(*s)
> 	{
> 		if(*s>='0'&&*s<='9'||*s>='a'&&*s<='f'||*s>='A'&&*s<='F')
> 			s++;
> 		else 
> 			return 0;
> 	}
> 	return 1;
> }
> 
> static void requestRSIMReadPbRecord(RIL* thiz, void *data, size_t datalen, RIL_Token t, const char* storage)
> {
> 	ATResponse* recordResp = NULL;
> 	char cmd[32];
> 	char* number;
> 	char* text;
> 	int number_type;
> 	int ignored;
> 	char recordSimResp[256];
> 	RIL_SIM_IO_Response sr;
> 	RIL_SIM_IO_v5 *p_args;
> 
> 	memset(&sr, 0, sizeof(sr));
> 	memset(recordSimResp, 0, 256);
> 	p_args = (RIL_SIM_IO_v5 *)data;
> 	
> 	if(p_args->pin2 == NULL) {
> 		snprintf(cmd, 32, "AT+CPBS=\"%s\"", storage);
> 	} else {
> 		snprintf(cmd, 32, "AT+CPBS=\"%s\",\"%s\"", storage, p_args->pin2);
> 	}
> 	ril_command_exec_for_result(thiz, cmd);
> 	ril_command_exec_for_result(thiz, "AT+CSCS=\"UCS2\"");
> 	snprintf(cmd, 32, "AT+CPBR=%d,%d", p_args->p1, p_args->p1);
> 	if(ril_command_exec_singleline_for_result(thiz, cmd, "+CPBR:", &recordResp))
> 	{
> 		PbookInfo pb_info;
> 		unsigned char* efData = NULL;
> 		int efDataLen = 0;
> 		char* hexStr;
> 
> 		if(recordResp->p_intermediates->line != NULL) {
> 			at_line_scanf_int_string_int_string_int(recordResp->p_intermediates->line,
> 				&pb_info.index, &number, &number_type, &text, &ignored);
> 			
> 			if(number != NULL && number[0] == '+')
> 			{
> 				number++;
> 			}
> 			
> 			pb_info.number = (unsigned char*)number;
> 			pb_info.number_len = strlen(number);
> 			pb_info.number_type = number_type;
> 		
> 			if(isHexStr(text) && strlen(text) > 2 && !strncmp(text, "80", 2))   
> 			{
> 				pb_info.text = StringToHex(text+2, strlen(text)-2);
> 				pb_info.text_len = (strlen(text) - 2)/2; 
> 				pb_info.coding = RAW;
> 			}
> 			else 
> 			{
> 				pb_info.text = text;
> 				pb_info.text_len = strlen(text); 
> 				pb_info.coding = ASCII;
> 			}
> 
> 			ruim_pbook_encode(&pb_info, &efData, &efDataLen);
> 			hexStr = hexToString(efData, efDataLen);
> 			strcpy(recordSimResp, hexStr);
> 		
> 			at_response_free(recordResp);
> 			free(efData);
> 			free(hexStr);
> 			//free(pb_info.text);
> 		}
> 	}
> 
> 	if(strlen(recordSimResp) == 0)
> 	{
> 		memset(recordSimResp, 'F', p_args->p3  * 2);
> 	}
> 
> 	sr.simResponse = recordSimResp;
> 	ALOGD("%s: simResponse=%s", __func__, sr.simResponse);
> 	sr.sw1 = 0x90;
> 	sr.sw2 = 0x00;
> 	RIL_onRequestComplete(thiz, t, RIL_E_SUCCESS, &sr, sizeof(sr));
> 
> 	return;
> }
> 
> static void requestRSIMPbResponse(RIL* thiz, void *data, size_t datalen, RIL_Token t, const char* storage)
> {
> 	RIL_SIM_IO_Response sr;
> 	ATResponse* sizeResp = NULL;
> 	int size = 0;
> 	int text_size = 0;
> 	char* ignored_str;
> 	int ignored;
> 	char pathSimResp[64];
> 	char cmd[32];
> 	RIL_SIM_IO_v5 *p_args;
> 
> 	memset(&sr, 0, sizeof(sr));
> 	memset(pathSimResp, 0, 64);
> 	p_args = (RIL_SIM_IO_v5 *)data;
> 	
> 	if(p_args->pin2 == NULL) {
> 		snprintf(cmd, 32, "AT+CPBS=\"%s\"", storage);
> 	} else {
> 		snprintf(cmd, 32, "AT+CPBS=\"%s\",\"%s\"", storage, p_args->pin2);
> 	}
> 	ril_command_exec_for_result(thiz, cmd);
> 	if(ril_command_exec_singleline_for_result(thiz, "AT+CPBS?", "+CPBS", &sizeResp))
> 	{
> 		at_line_scanf_string_int_int(sizeResp->p_intermediates->line, &ignored_str, &ignored, &size);
> 	}
> 
> 	if(ril_command_exec_singleline_for_result(thiz, "AT+CPBR=?", "+CPBR:", &sizeResp)) 
> 	{
> 		at_line_scanf_string_int_int(sizeResp->p_intermediates->line, &ignored_str, &ignored, &text_size);
> 		ALOGD("requestSIM_IO: text_size=%d,size=%d\n", text_size, size);
> 		size = (size * (text_size + 14));
> 		snprintf(pathSimResp, 64, "0000%04X6F3C0400110055010201%02X", size, text_size + 14);
> 
> 		ALOGD("requestSIM_IO: response=%s\n", pathSimResp);
> 		at_response_free(sizeResp);
> 	}
> 
> 	sr.simResponse = pathSimResp;	
> 	sr.sw1 = 0x90;
> 	sr.sw2 = 0x00;
> 	RIL_onRequestComplete(thiz, t, RIL_E_SUCCESS, &sr, sizeof(sr));
> 
> 	return;
> }
> 
> static void requestAdnIo(RIL* thiz, void *data, size_t datalen, RIL_Token t)
> {
> 	RIL_SIM_IO_v5 *p_args;
> 
> 	p_args = (RIL_SIM_IO_v5 *)data;
> 	if(p_args->command == 192) {
> 		requestRSIMPbResponse(thiz, data, datalen, t, PB_STORAGE_SM);
> 	} else if(p_args->command == 178 ){
> 		requestRSIMReadPbRecord(thiz, data, datalen, t, PB_STORAGE_SM);
> 	} else if(p_args->command == 220) {
> 		requestRSIMWritePbRecord(thiz, data, datalen, t, PB_STORAGE_SM);
> 	}
> 
> 	return;
> }
> /*wupeng add end.*/
> 
> static void getRSIMSmsResponse(RIL* thiz, char* pathSimResp)
> {
> 	ATResponse* sizeResp = NULL;
> 	int size = 0;
> 	char* ignored_str;
> 	int ignored;
> 
> 	if(ril_command_exec_singleline_for_result(thiz, "AT+CPMS?", "+CPMS:", &sizeResp)) 
> 	{
> 		at_line_scanf_string_int_int(sizeResp->p_intermediates->line, &ignored_str, &ignored, &size);
> 		ALOGD("requestSIM_IO: size=%d\n", size);
> 		size = size * 176;
> 		snprintf(pathSimResp, 64, "0000%04X6F3C0400110055010201B0", size);
> 		
> 		ALOGD("requestSIM_IO: response=%s\n", pathSimResp);
> 		at_response_free(sizeResp);
> 	}
> 
> 	return;
> }
> 
200a446
> 	char pathSimResp[64];
204a451,457
> 	/*wupeng add begin.*/
> 	if(p_args->fileid == 28474) {
> 		requestAdnIo(thiz, data, datalen, t);
> 
> 		return;
> 	}
> 	/*wupeng add end.*/
209,211c462,464
<         asprintf(&cmd, "AT+CRSM=%d,%d,%d,%d,%d,0,\"%s\"",
<                     p_args->command, p_args->fileid,
<                     p_args->p1, p_args->p2, p_args->p3, p_args->path);
---
> 		asprintf(&cmd, "AT+CRSM=%d,%d,%d,%d,%d,0,\"%s\"",
> 				p_args->command, p_args->fileid,
> 				p_args->p1, p_args->p2, p_args->p3, p_args->path);
213c466
<         asprintf(&cmd, "AT+CRSM=%d,%d,%d,%d,%d,%s,%s,\"%s\"",
---
>         asprintf(&cmd, "AT+CRSM=%d,%d,%d,%d,%d,%s,\"%s\"",
239a493,501
> 	/*TODO: TD CARD BUG*/
> 	memset(pathSimResp, 0, 64);
> 	if(p_args->fileid == 28476 && p_args->command == 192 && strlen(sr.simResponse) > 40) {
> 		getRSIMSmsResponse(thiz, pathSimResp);	
> 		sr.simResponse = pathSimResp;
> 	} else if(p_args->fileid == 28476 && p_args->command == 178) {
> 		asprintf(&cmd, "AT+CMGR=%d", p_args->p1 - 1);
> 		ril_command_exec_for_result(thiz, cmd);
> 	}
